package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.ServiceOfferConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.joda.time.LocalDate;

/**
 * @Classname RequiredDateAttrHandler
 * @Description 时间类型字段，默认当前时间+n天
 * @Author zhang.song
 * @Date 2021-02-23 10:01
 */
public class RequiredDateAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {


    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        super.after(attr, inst, data);

        // 订购、核查 操作
        if (KiteStringUtils.equalsAny(data.getServiceOfferId(), ServiceOfferConsts.SERVICE_OFFER_ORDER, LocalServiceOfferConsts.SERVICE_OFFER_RESOURCE_CHECK)) {
            if (KiteStringUtils.isEmpty(attr.getValue())) {
                String productId = inst.getSpecId();
                LocalDate nowDate = LocalDate.now();
                // 追加天数
                String value = nowDate.plusDays(getAddDays(productId)).toString();
                attr.setValue(value);
            }
        }
    }
    /**
     * 不同产品默认 当日往后加天数getAddDays
     */
    private static int getAddDays(String productId) {
        int result = 3;
        switch (productId) {
            case "10003665":
                result = 5;
                break;
            default:
                break;
        }
        return result;
    }
}
